<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>ECharts-tooltip-提示框组件</title>
  </head>
  <body>
    <div id="main" style="height: 400px"></div>
    <script src="../libs/echarts-5.3.3.js"></script>
    <script>
      window.onload = function () {
        let myChart = echarts.init(document.getElementById("main"));
        let option = {
          backgroundColor: "rgba(255, 0, 0, 0.1)",
          grid: {
            show: true,
            backgroundColor: "rgba(0, 255, 0, 0.1)",
          },
          // 提示框组件
          tooltip: {
            show: true,
            // 使用了 trigger ，一般也结合 axisPointer
            trigger: "axis", // 默认是 item
            // 坐标轴指示器，坐标轴触发有效
            axisPointer: {
              type: "shadow", //  (默认是竖线 line)  (横线 + 竖线 cross)  (横线 + 竖线 shadow)
            },
            formatter: function (params) {
              console.log(params);
              return `<div style="color:red">${params[0].axisValue}</div>`;
            },
          },

          xAxis: {
            data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
          },
          yAxis: {},
          series: [
            {
              type: "bar",
              data: [5, 20, 36, 10, 10, 20],
            },
          ],
        };
        myChart.setOption(option);
      };
    </script>
  </body>
</html>
